import { DIS_STATUSBANDBTNTEXT, STATUSBAND } from '@/constant'
import { Badge, Button, Popconfirm, Space, TableColumnsType, Tag, Typography } from 'antd'
import { useNavigate } from 'react-router-dom'
import type { ITableData } from './types'
export const useIndexColumns = (
  onEdit: (id: number) => void,
  onDel: (id: number) => void,
  onStatus: (info: ITableData) => void,
  params: Record<string, any>,
): TableColumnsType<ITableData> => [
  {
    title: '组织名称',
    dataIndex: 'orgName',
    key: 'orgName',
    align: 'center',
    width: 150,
    render: (info) => {
      return info ? info : '-'
    },
  },
  {
    title: '所属应用',
    dataIndex: 'applicationName',
    key: 'applicationName',
    align: 'center',
    width: 150,
    render: (info) => {
      return info ? info : '-'
    },
  },
  {
    title: '角色名称',
    dataIndex: 'roleName',
    key: 'roleName',
    align: 'center',
    width: 150,
    render: (info) => {
      return info ? info : '-'
    },
  },
  {
    title: '角色描述',
    dataIndex: 'roleDesc',
    key: 'roleDesc',
    align: 'center',
    width: 150,
    render: (info) => {
      return info ? info : '-'
    },
  },
  {
    title: '角色状态',
    dataIndex: 'status',
    key: 'status',
    align: 'center',
    width: 150,
    render: (info) => {
      return <Badge status={info == 1 ? 'success' : 'error'} text={STATUSBAND[info] || '-'} />
    },
  },
  {
    fixed: 'right',
    title: '操作',
    width: 200,
    align: 'center',
    render: (info) => {
      return (
        <Space size="large">
          <Typography.Link onClick={() => onEdit(info.id)}>详情</Typography.Link>
          <Popconfirm
            title={`确认${DIS_STATUSBANDBTNTEXT[info.status]}吗？`}
            onConfirm={() => onStatus(info)}
            okText="确认"
            cancelText="取消"
          >
            <Typography.Link type={info.status == 1 ? 'danger' : undefined}>
              {DIS_STATUSBANDBTNTEXT[info.status]}
            </Typography.Link>
          </Popconfirm>
          <Popconfirm title={`确认删除吗？`} onConfirm={() => onDel(info.id)} okText="确认" cancelText="取消">
            <Typography.Link type="danger">删除</Typography.Link>
          </Popconfirm>
        </Space>
      )
    },
  },
]
